package com.blog.blog.controller;

import com.blog.blog.service.impl.SysUserServiceImpl;
import com.blog.blog.utils.UserThreadLocal;
import com.blog.blog.vo.Result;
import com.blog.blog.vo.WebResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("users")
public class UsersController {

    @Autowired
    SysUserServiceImpl sysUserService;

    @GetMapping("currentUser")
    public Result currentUser(@RequestHeader("Authorization") String ticket) {
        return sysUserService.getUserInfoByToken(ticket);
    }

    @GetMapping("getUserInfo")
    public WebResult<Map<String,Object>> getUserInfo() {
        return WebResult.<Map<String, Object>>builder()
                .code(200)
                .message(WebResult.REQUEST_STATUS_SUCCESS)
                .data(sysUserService.getUserInfo())
                .build();
    }

}